package com.cqcj.wms.service.impl;

import com.cqcj.wms.entity.StoreMain;
import com.cqcj.wms.mapper.StoreMainMapper;
import com.cqcj.wms.service.IStoreMainService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author：zhouxiaobao
 * @name：IStoreMainServiceImpl
 * @Date：2024/10/17 14:27
 */
@Service
public class IStoreMainServiceImpl implements IStoreMainService{

    @Autowired
    private StoreMainMapper storeMainMapper;


    @Override
    public List<StoreMain> list() {
        return storeMainMapper.list();
    }

    @Override
    public int insert(StoreMain storeMain) {
        return storeMainMapper.insert(storeMain);
    }

    @Override
    public int update(StoreMain storeMain) {
        return storeMainMapper.update(storeMain);
    }

    @Override
    public int delete(int id) {
        return storeMainMapper.delete(id);
    }

    @Override
    public StoreMain getEntityById(int id) {
        return storeMainMapper.getEntityById(id);
    }

    @Override
    public PageInfo<StoreMain> pageList(int pageNum, int pageSize) {
        if(pageNum < 1){
            pageNum = 1;
        }
        //借助PageHelper工具类开启分页
        PageHelper.startPage(pageNum, pageSize);
        //查询仓库列表
        List<StoreMain> goodList = storeMainMapper.list();
        //将仓库列表信息封装到PageInfo对象中
        PageInfo<StoreMain> pageInfo = new PageInfo<>(goodList);
        return  pageInfo;
    }

    /**
     * 根据条件查询分页
     * @param pageNum
     * @param pageSize
     * @param storeMain
     * @return
     */
    @Override
    public PageInfo<StoreMain> pageByConditionList(int pageNum, int pageSize, StoreMain storeMain) {
        if(pageNum < 1){
            pageNum = 1;
        }
        //借助PageHelper工具类开启分页
        PageHelper.startPage(pageNum, pageSize);
        //查询仓库列表
        List<StoreMain> storeMainList = storeMainMapper.listByVendor(storeMain);
        //将仓库列表信息封装到PageInfo对象中
        PageInfo<StoreMain> pageInfo = new PageInfo<>(storeMainList);
        return  pageInfo;
    }
}
